package com.inspectortime.webapp.inspector;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;

import com.inspectortime.domain.Scheduler;
import com.inspectortime.util.SpringValidatorUtils;

/**
 * Add a new Inspector to an existing company
 * 
 * @author bones
 *
 */
public class EditSchedulerController extends EditEmployeeController {
	
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		String id = request.getParameter("id");
		Scheduler scheduler = repository.loadScheduler(id);
		scheduler.setEmailConfirm(scheduler.getEmail());
		
		// Trick to not validate for uniqueness if no change
		scheduler.setOldEmail(scheduler.getEmail());
		scheduler.setOldUserName(scheduler.getUserName());

		return scheduler;
	}
	
	private static Log log = LogFactory.getLog(EditSchedulerController.class);
	protected void onBindAndValidate(HttpServletRequest request,
			Object command, BindException errors) throws Exception {
		SpringValidatorUtils.logValidationErrors(log, errors);
	}
	
}
